package com.yh.correct.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yh.correct.dao.IMovePersonnelMapper;
import com.yh.correct.model.CorrectedPerson;
import com.yh.correct.model.JudicialDeptment;
import com.yh.correct.model.Page;
import com.yh.correct.service.IMovePersonnelService;


/**
 * 居住地变更业务层实现类
 */
@Service
public class MovePersonnelServiceImpl implements IMovePersonnelService{
	/**
	 * logger4j日志
	 */
	private static Logger logger = LogManager.getLogger(MovePersonnelServiceImpl.class);
	
	@Autowired
	private IMovePersonnelMapper movepersonnelmapper;
	/**
	 * 
	 */
	@Override
	public Page getMovePersonnelByPage(Map<String, Object> movepersonnel){
		Page page = new Page();

		try {
			int curPageNum = Integer.parseInt(String.valueOf(movepersonnel.get("curPageNum")));
			page.setCurPageNum(curPageNum);
			int pageSize = Integer.parseInt(String.valueOf(movepersonnel.get("pageSize")));
			page.setPageSize(pageSize);
			double tatolNum = movepersonnelmapper.getMoveRegisterCount(movepersonnel);
			Double tn= Math.ceil(tatolNum/pageSize);
			page.setTotalPage(tn.intValue());
			page.setResult(movepersonnelmapper.getMoveRegister(movepersonnel));
		} catch (Exception e) {
			logger.debug("出现异常!");
			e.printStackTrace();
		}
		return page;
	}
	/**
	 * 查询所有矫正单位
	 */
	@Override
	public List<JudicialDeptment> findAllJudicialDeptment() {
		List<JudicialDeptment> list = null;
		try {
			list = movepersonnelmapper.getAllJudicialDeptment();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
	/**
	 * 根据id关联查询服刑人员详情
	 */
	@Override
	public List<Object> getDetail(int id) {
		List<Object> list = null;
		try {
			list = movepersonnelmapper.getDetail(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
	/**
	 * 修改迁居人员信息
	 */
	@Override
	public int updateMovePersonel(Map<String, Object> map) {
		int i = 0;
		try {
			i = movepersonnelmapper.updateMovePersonel(map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return i;
	}
	/**
	 * 删除迁居人员信息
	 */
	@Override
	public int deleteMovePersonelById(int id) {
		int i = 0;
		try {
			i = movepersonnelmapper.deleteMovePersonelById(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return i;
	}
	/**
	 * 添加迁居信息
	 */
	@Override
	public int addMovePersonelMessage(Map<String,Object> map) {
		int i = 0;
		try {
			i = movepersonnelmapper.addMovePersonelMessage(map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return i;
	}
	/**
	 * 由于显示列表所有信息
	 */
	@Override
	public List<Map<String,Object>> getMovePersonnel() {
		List<Map<String,Object>> list = null;
		try {
			list = movepersonnelmapper.getMovePersonnel();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
	/**
	 * 根据id查询相关信息
	 */
	@Override
	public Map<String, Object> getMovePersonnelById(int id) {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			map = movepersonnelmapper.getMovePersonnelById(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}
	/**
	 * 批量删除
	 */
	@Override
	public int deleteBatch(List<Integer> list) {
		int i = 0;
		try {
			i = movepersonnelmapper.deleteBatch(list);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return i;
	}
	/**
	 * 根据矫正单位id 查询此矫正单位下的所有矫正人员
	 */
	@Override
	public List<CorrectedPerson> findCorrectedPersonByJid(int id) {
		List<CorrectedPerson> list = new ArrayList<CorrectedPerson>();
		try {
			list = movepersonnelmapper.getCorrectedPersonByJid(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
}
